package com.ruoyi.system.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.RegistrationType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Scheduling;
import com.ruoyi.system.service.ISchedulingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排班Controller
 * 
 * @author ruoyi
 * @date 2024-02-26
 */
@RestController
@DataSource(DataSourceType.HOSSCHEDULING)
@RequestMapping("/system/scheduling")
public class SchedulingController extends BaseController
{
    @Autowired
    private ISchedulingService schedulingService;

    /**
     * 查询排班列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:list')")
    @GetMapping("/list")
    public TableDataInfo list(Scheduling scheduling)
    {
        startPage();
        List<Scheduling> list = schedulingService.selectSchedulingList(scheduling);
        return getDataTable(list);
    }

    /**
     * 导出排班列表
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:export')")
    @Log(title = "排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Scheduling scheduling)
    {
        List<Scheduling> list = schedulingService.selectSchedulingList(scheduling);
        ExcelUtil<Scheduling> util = new ExcelUtil<Scheduling>(Scheduling.class);
        util.exportExcel(response, list, "排班数据");
    }

    /**
     * 获取排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(schedulingService.selectSchedulingById(id));
    }

    /**
     * 新增排班
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:add')")
    @Log(title = "排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Scheduling scheduling)
    {
        scheduling.setDel(0L);
        return toAjax(schedulingService.insertScheduling(scheduling));
    }

    /**
     * 修改排班
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:edit')")
    @Log(title = "排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Scheduling scheduling)
    {
        return toAjax(schedulingService.updateScheduling(scheduling));
    }

    /**
     * 删除排班
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:remove')")
    @Log(title = "排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(schedulingService.deleteSchedulingByIds(ids));
    }

    @GetMapping("/findSc/{dId}")
    public TableDataInfo findSc(@PathVariable String dId, @RequestParam String date)
    {
        List<Scheduling> list = schedulingService.findScheduling(dId, date);
        return getDataTable(list);
    }

//    public static void main(String[] args) {
//        Map<String, String> map = new HashMap<>();
//        map.put("1","10");
//        map.put("2","10");
//        map.put("3","10");
//        map.put("4","10");
//        String string = JSON.toJSONString(map);
//        Map sss = JSON.toJavaObject("{\"1\":\"10\",\"2\":\"10\",\"3\":\"10\",\"4\":\"10\"}", Map.class);
//        System.out.println(sss.get(1));
////        System.out.println(string);
//    }
}
